package top.maochang.hou.dao.impl;


import top.maochang.hou.dao.MenuDao;
import top.maochang.hou.entity.SysMenu;
import top.maochang.hou.entity.SysUser;
import top.maochang.hou.utils.JDBCUtlis;

import java.sql.SQLException;
import java.util.List;

public class MenuDaoImpl implements MenuDao {

    @Override
    public List<SysMenu> queryListMenuByUserId(SysUser user) throws SQLException {
        String sql = "select  \n" +
                "m.id as id,\n" +
                "m.parent_id as parentId,\n" +
                "m.`name` as  name,\n" +
                "m.type as type,\n" +
                "m.path as path,\n" +
                "m.component as component,\n" +
                "m.perms as perms,\n" +
                "m.icon as icon,\n" +
                "m.sort_value as sortValue,\n" +
                "m.`status` as  `status`,\n" +
                "m.create_time as  createTime,\n" +
                "m.update_time as  updateTime,\n" +
                "m.is_deleted as   isDeleted\n" +
                "from  sys_menu  m   \n" +
                "          inner join sys_role_menu rm  on m.id=rm.menu_id\n" +
                "          inner join sys_user_role ur  on ur.role_id=rm.role_id\n" +
                "\t\t\t\t\tWHERE ur.user_id=?\n" +
                "\t\t\t\t\tAND rm.is_deleted = 0\n" +
                "          AND ur.is_deleted = 0\n" +
                "          AND m.is_deleted = 0";
        return JDBCUtlis.queryForList(SysMenu.class, sql,user.getId());
    }

}
